package com.iterator.controller.web.systemManager;



import com.iterator.bean.web.pojo.BaseRespVo;
import com.iterator.bean.web.wy.storage.Storage;

import com.iterator.bean.web.wy.storage.StorageVO;
import com.iterator.bean.web.wy.storage.UpdateStorageVO;
import com.iterator.service.web.systemManager.StorageService;
import com.iterator.util.StringTrim;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: Silence_W
 * @date: 2021-01-10 17:04
 *
 * 系统管理
 *   对象存储
 *
 *
 **/
@RestController
@RequestMapping("admin/storage")
public class StorageController {

    @Autowired
    StorageService storageService;

    //对象存储的数据显示
    @RequestMapping("list")
    @RequiresPermissions("admin:storage:list")
    public BaseRespVo list(Integer page, Integer limit, String key, String name, String sort, String order) {
        String trim = StringTrim.trim(key);
        String trim1 = StringTrim.trim(name);
        StorageVO storageVO = storageService.queryStorage(page, limit, trim, trim1, sort, order);
        return BaseRespVo.ok(storageVO);
    }

    @RequestMapping("create")
    @RequiresPermissions("admin:storage:create")
    public BaseRespVo create(MultipartFile file, HttpServletRequest request){
        Storage storage = storageService.create(file,request);
        if (storage != null) {
            return BaseRespVo.ok(storage);
        }
        return BaseRespVo.fail("图片上传失败");
    }

    //对象存储的更新
    @RequestMapping("update")
    @RequiresPermissions("admin:storage:update")
    public BaseRespVo update(@RequestBody Storage storage){
       UpdateStorageVO updateStorageVO= storageService.updateStorage(storage);
       return  BaseRespVo.ok(updateStorageVO);
    }
    @RequestMapping("delete")
    @RequiresPermissions("admin:storage:delete")
    public BaseRespVo delete(@RequestBody Storage storage){
        storageService.delete(storage.getId());
        return BaseRespVo.ok();
    }
}
